package com.cdcas.selfIteror;

import java.util.Iterator;

public class Book implements Iterable<Book>{
    private String title;
    private int foot = 0;
    public Book(){}
    public Book(String title) {
        this.title = title;
    }
    private static final Book ALL[] = new Book[]{new Book("java"),
            new Book("C"),new Book("python")};

    @Override
    public String toString() {
        return "Book{" +
                "title='" + title + '\'' +
                '}';
    }

    @Override
    public Iterator<Book> iterator() {
        return new BookIter();
    }

  private class  BookIter implements Iterator<Book>{

      @Override
      public boolean hasNext() {
          return Book.this.foot <Book.ALL.length;
      }

      @Override
      public Book next() {
          return Book.ALL[Book.this.foot++];
      }
  }
}


